﻿@using Citi.EmailSender.Domain
@model IEnumerable<Citi.EmailSender.WebUi.Models.EmailModel>
@if (Model == null || !Model.Any())
{
    <p>
        There are no approvals</p>
    return;
}
<table class="table table-bordered table-striped">
    <tr>
        <th>
            Create On
        </th>
        <th>
            Application
        </th>
        <th>
            On Behalf Of
        </th>
        <th>
            Subject
        </th>
        <th>
            Receivers
        </th>
        <th>
            Schedule Date
        </th>
        <th>
        </th>
    </tr>
    @foreach (var item in Model)
    {
        <tr>
            <td>
                @item.CreatedDate.ToString()
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.EmailData.Application.FullName)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.EmailData.OnBehalfOf.FriendlyName)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.EmailData.Subject)
            </td>
            <td>
                @if (item.EmailReceivers.Any(x => x.Type == Enums.EmailReceiverType.To))
                {
                    <div>
                        <strong>To:</strong>
                        @string.Join("; ", item.EmailReceivers.Where(x => x.Type == Enums.EmailReceiverType.To).Select(x => x.EmailAddress.Address))
                    </div>
                }
                @if (item.EmailReceivers.Any(x => x.Type == Enums.EmailReceiverType.Cc))
                {
                    <div>
                        <strong>Cc:</strong>
                        @string.Join("; ", item.EmailReceivers.Where(x => x.Type == Enums.EmailReceiverType.Cc).Select(x => x.EmailAddress.Address))
                    </div>
                }
                @if (item.EmailReceivers.Any(x => x.Type == Enums.EmailReceiverType.Bcc))
                {
                    <div>
                        <strong>Bcc:</strong>
                        @string.Join("; ", item.EmailReceivers.Where(x => x.Type == Enums.EmailReceiverType.Bcc).Select(x => x.EmailAddress.Address))<br />
                    </div>
                }
            </td>
            <td>
                @(item.ScheduleDate.HasValue ? item.ScheduleDate.Value.ToString("MM/dd/yyyy HH:mm") : string.Empty)
            </td>
            <td>
                @Html.ActionLink("Preview", "Preview", "Email", new { id = item.Id }, new { target = "_blank" })
                @if (!item.Approved.HasValue)
                {   
                    <text>|</text>
                    @Html.ActionLink("Approve", "Approve", new { id = item.Id })
                    <text>|</text>
                    @Html.ActionLink("Disapprove", "Disapprove", new { id = item.Id })
                }
            </td>
        </tr>
    }
</table>
